package com.yanboo.modules.mnt.rest;

import com.yanboo.common.annotation.CustomController;
import com.yanboo.modules.mnt.service.DeployHistoryService;
import com.yanboo.modules.mnt.service.dto.DeployHistoryDto;
import com.yanboo.modules.mnt.service.dto.DeployHistoryQueryCriteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import com.yanboo.logging.annotation.Log;
import com.yanboo.common.utils.PageResult;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Set;

/**
 * 运维：部署历史管理
 */
@Tag(name = "运维：部署历史管理")
@CustomController
@RequiredArgsConstructor
@RequestMapping("/api/deployHistory")
public class DeployHistoryController {

    private final DeployHistoryService deployhistoryService;

    /**
     * 导出部署历史数据
     * @param response
     * @param criteria
     * @throws IOException
     */
    @Operation(summary = "导出部署历史数据")
    @GetMapping(value = "/download")
    public void exportDeployHistory(HttpServletResponse response, DeployHistoryQueryCriteria criteria) throws IOException {
        deployhistoryService.download(deployhistoryService.queryAll(criteria), response);
    }

    /**
     * 查询部署历史
     * @param criteria
     * @param pageable
     * @return
     */
    @Operation(summary = "查询部署历史")
    @GetMapping
    public ResponseEntity<PageResult<DeployHistoryDto>> queryDeployHistory(DeployHistoryQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(deployhistoryService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
     * 删除部署历史
     * @param ids
     * @return
     */
    @Operation(summary = "删除部署历史")
    @Log("删除DeployHistory")
	@DeleteMapping
    public ResponseEntity<Object> deleteDeployHistory(@RequestBody Set<String> ids){
        deployhistoryService.delete(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
